import {Injectable} from '@angular/core';
import {environment} from "../../../../../../environments/environment";
import {HttpUtilService} from "../../../../../services/http/http-util.service";
import {BarnSql} from "../entity/barn-sql";
import {Observable} from "rxjs";
import {ResponseEntity} from "../../../../../services/http/response-entity";
import {MoveSingleSql} from "./dto/move-single-sql";

@Injectable({
  providedIn: 'root'
})
export class BarnSqlService {

  private prefix = environment.serverName.document + "/sql/"
  private export_prefix = environment.serverName.document + "/sqlExport/"

  constructor(private http: HttpUtilService) {
  }

  save(sql: BarnSql, handleError = true): Observable<BarnSql> {
    return this.http.post(this.prefix + "save", sql, handleError);
  }

  getById(pid: string, handleError = true): Observable<BarnSql> {
    return this.http.get(this.prefix + "getById/" + pid, handleError)
  }

  queryMySql(param: BarnSql, current = 0, pageSize = 0, handleError = true): Observable<ResponseEntity<BarnSql[]>> {
    return this.http.getPage(this.prefix + 'queryMySql', current, pageSize, handleError, param)
  }

  deleteById(param: BarnSql, handleError = true): Observable<void> {
    return this.http.post(this.prefix + "deleteById", param, handleError)
  }

  query(param: BarnSql, current = 0, pageSize = 0, handleError = true): Observable<ResponseEntity<BarnSql[]>> {
    return this.http.getPage(this.prefix + 'queryAll', current, pageSize, handleError, param);
  }

  /**
   * 移动一条sql
   * @param param
   * @param handleError
   */
  moveOneSql(param: MoveSingleSql, handleError = true): Observable<void> {
    return this.http.post(this.prefix + "moveOneSql", param, handleError)
  }

  /**
   * 批量导出sql
   * @param param sql的查询条件
   * @param handleError
   */
  export(param: BarnSql, handleError = true) {
    return this.http.get(this.export_prefix, handleError,param)
  }

}
